package com.xasz.config;

import com.xasz.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration //加载当前的拦截器
class LoginInterceptorConfigurer implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //自定义拦截器对象
        HandlerInterceptor interceptor=new LoginInterceptor();
        //白名单
        List<String> patterns = new ArrayList<>();
        patterns.add("/user/reg");
        patterns.add("/user/login");

        //拦截器注册
        registry.addInterceptor(interceptor)
                //拦截的目标
                .addPathPatterns("/**")
                //不拦截的目标
                .excludePathPatterns(patterns);
    }
}